package com.tom.commonframework.common.http;

import android.content.Context;
import android.text.TextUtils;

import com.tom.commonframework.common.base.utils.SharePreferenceUtils;


/**
 * Created by Tomleisen on 2016/9/18 0018.
 */
public enum LocalInfoControlCenter {

    INSTANCES;

    private static final String TOKEN = "token";
    private static final String USERID = "userId";
    private static final String LOGIN_PHONE = "login_phone";
    private String token = "";
    private Integer userId = 0;
    private String loginPhone = "";

    private int env = 0;
    private boolean log_debug;
    private Context context;

    public void init(Context context) {
        this.context = context;
    }

    public int getEnv() {
        return env;
    }

    public void setEnv(int env) {
        this.env = env;
    }

    public boolean isLog_debug() {
        return log_debug;
    }

    public void setLog_debug(boolean log_debug) {
        this.log_debug = log_debug;
    }

    public String getToken() {
        if (TextUtils.isEmpty(token)) {
            token = SharePreferenceUtils.getString(context, TOKEN);
        }
        return token;
    }

    public void setToken(String token) {
        this.token = token;
        SharePreferenceUtils.setValue(context, TOKEN, token);
    }

    public Context getContext() {
        return context;
    }

    public void setContext(Context context) {
        this.context = context;
    }

    public Integer getUserId() {
        if (0 == userId) {
            userId = SharePreferenceUtils.getInt(context, USERID);
        }
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
        SharePreferenceUtils.setValue(context, USERID, userId);
    }

    public String getLoginPhone() {
        if (TextUtils.isEmpty(loginPhone)) {
            loginPhone = SharePreferenceUtils.getString(context, LOGIN_PHONE);
        }
        return loginPhone;
    }

    public void setLoginPhone(String loginPhone) {
        this.loginPhone = loginPhone;
        SharePreferenceUtils.setValue(context, LOGIN_PHONE, loginPhone);
    }
}
